package com.sylar.happygps;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TextView.OnEditorActionListener;

public class MainActivity extends Activity implements OnClickListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		View tv_metting = findViewById(R.id.tv_metting);
		tv_metting.setOnClickListener(this);
		View tv_tour = findViewById(R.id.tv_tour);
		tv_tour.setOnClickListener(this);
		View tv_collection = findViewById(R.id.tv_collection);
		tv_collection.setOnClickListener(this);
		View tv_map = findViewById(R.id.tv_map);
		tv_map.setOnClickListener(this);
		View tv_usercenter = findViewById(R.id.tv_usercenter);
		tv_usercenter.setOnClickListener(this);
		View tv_life = findViewById(R.id.tv_life);
		tv_life.setOnClickListener(this);
		View tv_usermanual = findViewById(R.id.tv_usermanual);
		tv_usermanual.setOnClickListener(this);
		View tv_cooperator = findViewById(R.id.tv_cooperator);
		tv_cooperator.setOnClickListener(this);
		View tv_contactus = findViewById(R.id.tv_contactus);
		tv_contactus.setOnClickListener(this);
		
		
		//搜索
		EditText ed_search = (EditText) findViewById(R.id.ed_search);
		ed_search.setOnEditorActionListener(new OnEditorActionListener() {
			
			@Override
			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
				if(actionId == EditorInfo.IME_ACTION_SEARCH){
					Intent intent = new Intent(getApplicationContext(),SearchResultActivity.class);
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(intent);
				}
				return false;
			}
		});
		
		View btn_search = findViewById(R.id.btn_search);
		btn_search.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(getApplicationContext(),SearchResultActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(intent);				
			}
		});
		
		
		ed_search.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

			}

			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
				Toast.makeText(getApplicationContext(), arg0, 0).show();
			}

			@Override
			public void afterTextChanged(Editable arg0) {

			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_metting:
			toMetting();
			break;
		case R.id.tv_tour:
			toTour();
			break;
		case R.id.tv_collection:
			toCollection();
			break;
		case R.id.tv_map:
			toMap();
			break;
		case R.id.tv_usercenter:
			toUsercenter();
			break;
		case R.id.tv_life:
			toLife();
			break;
		case R.id.tv_usermanual:
			toUsermanual();
			break;
		case R.id.tv_cooperator:
			toCooperator();
			break;
		case R.id.tv_contactus:
			toContactus();
			break;

		}
	}
	
	//跳转约会界面
	private void toMetting(){
		Intent intent = new Intent(this,MettingActivity.class);
		startActivity(intent);
	}
	
	//旅游
	private void toTour(){
		Intent intent = new Intent(this,TourActivity.class);
		startActivity(intent);
	}
	
	//导航收藏
	private void toCollection(){
		Intent intent = new Intent(this,FaviNavActivity.class);
		startActivity(intent);
	}
	
	//地图
	private void toMap(){
		Intent intent = new Intent(this,MapActivity.class);
		startActivity(intent);
	}
	
	//用户中心
	private void toUsercenter(){
		Intent intent = new Intent(this,UserCenterActivity.class);
		startActivity(intent);
	}
	
	//生活服务
	private void toLife(){
		Intent intent = new Intent(this,LifeActivity.class);
		startActivity(intent);
	}
	
	//用户手册
	private void toUsermanual(){
		Intent intent = new Intent(this,UserManualActivity.class);
		startActivity(intent);
	}
	
	//合作伙伴
	private void toCooperator(){
		Intent intent = new Intent(this,WebActivity.class);
		intent.putExtra("openurl", "http://www.dizhi114.com");
		startActivity(intent);
	}
	
	//联系我们
	private void toContactus(){
		Intent intent = new Intent(this,ContactusActivity.class);
		startActivity(intent);
	}
}
